/**
 * Turret.java
 */

package rainingcatsdogs;

import java.io.IOException;

import javax.microedition.lcdui.Image;

/**
 * The Turret class to hold information about the movable turret in the game
 */
public class Turret extends MovableObject {

	/**
	 * The amount of damage a created bullet does to an enemy
	 */
	private int bulletDamage = 1;
	
	/**
	 * The bullet image.
	 */
	private Image bulletImage;
	
	/**
	 * The number of pixels per frame for the bullet to travel at
	 */
	private int bulletSpeed;

	/**
	 * Construct a turret based on an initial image and location
	 * 
	 * @param explodeFrames
	 *            The number of frames it takes for the turret to explode
	 * @param image
	 *            The image for the turret, to be drawn to the canvas
	 * @param frameWidth
	 *            The width of one frame of the turret
	 * @param frameHeight
	 *            The height of one frame of the turret
	 * @param xPos
	 *            The initial x position of the turret
	 * @param yPos
	 *            The initial y position of the turret
	 */
	public Turret(int explodeFrames, Image image, int frameWidth,
			int frameHeight, int xPos, int yPos) {
		super(explodeFrames, image, frameWidth, frameHeight);
		this.setPosition(xPos, yPos);
		this.bulletSpeed = 5;
		try {
			bulletImage = Image.createImage("/bullet.png");
		} catch (IOException e) {
			System.err.println("Unable to load bullet image");
		}
	}

	/**
	 * This method creates a bullet object at the right position, with the right
	 * damage, and returns it to the caller
	 * 
	 * @return The created bullet object
	 */
	public Bullet shoot() {
		Bullet bullet = new Bullet(0, bulletImage, bulletImage.getWidth(),
				bulletImage.getHeight(), this.bulletDamage);

		bullet.setPosition(this.getX() + (this.getWidth() / 2), this.getY());
		bullet.setYStep(this.bulletSpeed);

		return bullet;
	}

	/**
	 * Increase the speed of bullets
	 * @param i
	 * 	The amount to increase the bullet speed by
	 */
	public void increaseBulletSpeed(int i) {
		this.bulletSpeed = this.bulletSpeed + i;
	}
}
